/*menu*/
function favoris() {
	$('#content').load('home/favoris',function(){
		initTreemap('infovis',IsFavoris,getData());
		policeTask();
		comptfavoris(getData());
	});
}

$(function(){
	routes['/favoris']=favoris;
			

});

function comptfavoris(allTasks) {
	var compteur=0;
	for (var i = 0; i < allTasks.length; i++) {
	    if (allTasks[i].favori == 1) {
			compteur=compteur+1;
		}
	}
	$('.cptTasks').text(compteur + " tâches");
}

function ajoutFavoris(id) {
    var allTasks = getData();
    var i = 0;
    while (id != allTasks[i].id) {
        i = i + 1;
    }

    var laTacheFavorite = { "id": allTasks[i].id, "objet": allTasks[i].objet, "priorite": allTasks[i].priorite, "date": allTasks[i].date, "description": allTasks[i].description, "lieu": allTasks[i].lieu, "couleur": allTasks[i].couleur, "historique": allTasks[i].historique, "favori": 1, "corbeille": 0 };
    //allTasks.splice(i, 1, { "id": allTasks[i].id, "objet": allTasks[i].objet, "priorite": allTasks[i].priorite, "date": allTasks[i].date, "description": allTasks[i].description, "lieu": allTasks[i].lieu, "couleur": allTasks[i].couleur, "historique": allTasks[i].historique, "favori": 1, "corbeille": 0 });

    lesTasks = saveFavoris(laTacheFavorite);
    accueil();
}

function saveFavoris(laTacheFavorite) {

    var json = JSON.stringify(laTacheFavorite);

    $.ajax({
        url: 'home/favoris',
        type: 'POST',
        dataType: 'json',
        data: json,
        contentType: 'application/json; charset=utf-8',
        success: function () {
            loadData(function () {
                accueil();
                //location.href = "/#/accueil";
            });
        }
    });

    //var lesnewTasks = loadData();

    //return lesnewTasks;
};